home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Grafik / Visage / Rexx / ShowVisage.dopus5 < prev    next >
Text File  |  1998-11-08  |  4KB  |  195 lines

  1. /* $VER: ShowVisage.dopus5 1.1 (6.8.98)
  2.  *
  3.  * Public domain by Magnus Holmgren.
  4.  *
  5.  * Shows the files selected in the source listers, by creating a temporary
  6.  * file list, and passing this to Visage via the LIST argument. This
  7.  * requires Visage 39.15 or better to work.
  8.  *
  9.  * Usage: ShowVisage.dopus5 PortName Lister VisageOpts
  10.  *
  11.  * PortName   : Name of Opus ARexx port.
  12.  * Lister     : Handle for lister to show files for. Use 0 to display files
  13.  *              for all current source listers.
  14.  * VisageOpts : Any options to pass to Visage.
  15.  *
  16.  * Select "Run Asyncronously" if you like...
  17.  *
  18.  *
  19.  * Version 1.0:
  20.  *     Initial release.
  21.  *
  22.  * Version 1.1:
  23.  *     Improved error message if there were no source listers available.
  24.  *
  25.  *     Can now show files for a certain lister only. Note that you need to
  26.  *     call the script a bit differently, even if you don't use this
  27.  *     feature.
  28.  *
  29.  *     Now makes the current lister busy while processing the entries. The
  30.  *     script should never leave a disabled lister behind, but...
  31.  */
  32.  
  33.  
  34. /* ---- Config section start ---- */
  35.  
  36. /* Complete path to the Visage executable. */
  37. VisagePath = 'Tools:View/Visage'
  38.  
  39. /* Path to drawer for the temporary list file. Must end with ':' or '/'. */
  40. TempPath   = 'T:'
  41.  
  42. /* ---- Config section end ---- */
  43.  
  44.  
  45. /* Initialize */
  46. Lf = '0a'x
  47. Handle = ''
  48.  
  49. OPTIONS RESULTS
  50. PARSE ARG Port ' ' ListerHandle ' ' VisageOpts
  51.  
  52. /* Make sure arguments are reasonable */
  53. IF Port = '' | ~Show( 'P', Port ) THEN DO
  54.     /* Might not be visible when started incorrectly from Opus. ;) */
  55.     SAY 'ShowVisage.dopus5:'
  56.     SAY 'Not correctly called from Directory Opus 5.'
  57.     SAY 'See the ARexx-script for more information.'
  58.     RETURN
  59. END
  60.  
  61. /* Talk to Directory Opus */
  62. ADDRESS VALUE Port
  63.  
  64. /* Activate break handling, since the script can take a while to finish */
  65. SIGNAL ON BREAK_C
  66.  
  67. /* Open temporary file, using a unique name */
  68. TempName = TempPath'ShowVisage.'Pragma( 'ID' )'.list'
  69.  
  70. IF ~Open( 'List', TempName, 'Write' ) THEN DO
  71.     CALL OpusMessage 'Couldn''t open temporary list file.'
  72.     RETURN
  73. END
  74.  
  75. IF ListerHandle = 0 THEN DO
  76.     /* Get all source listers */
  77.     Lister Query Source
  78.  
  79.     IF RC ~= 0 THEN DO
  80.         CALL OpusMessage 'Couldn''t find any source listers.'
  81.         SIGNAL Terminate
  82.     END
  83.  
  84.     Listers = RESULT
  85. END
  86. ELSE DO
  87.     /* Use argument lister handle */
  88.     Listers = ListerHandle
  89. END
  90.  
  91.  
  92. /* Process the source listers one by one */
  93. DO WHILE Listers ~= ''
  94.     PARSE VAR Listers Handle ' ' Listers
  95.  
  96.     IF ~SaveListerEntries( Handle ) THEN DO
  97.         SIGNAL Terminate
  98.     END
  99. END
  100.  
  101. /* Close generated file */
  102. IF ~Close( 'List' ) THEN DO
  103.     CALL OpusMessage 'Couldn''t write to temporary list file.'
  104.     SIGNAL Terminate
  105. END
  106.  
  107. /* We are now ready to display the files */
  108. ADDRESS COMMAND VisagePath' LIST "'TempName'" 'VisageOpts
  109. Command Delete '"'TempName'"' QUIET
  110.  
  111. RETURN
  112.  
  113.  
  114. Failed:
  115.     CALL OpusMessage 'Couldn''t get needed information.'
  116.     /* Fall through */
  117.  
  118.  
  119. /* Make a clean exit after break or error */
  120. BREAK_C:
  121. Terminate:
  122.     IF Handle ~= '' THEN DO
  123.         Lister Set Handle Busy Off
  124.     END
  125.  
  126.     CALL Close( 'List' )
  127.     Command Delete '"'TempName'"' QUIET
  128.     RETURN
  129.  
  130.  
  131. /* Save all selected entries in the specified lister to a file, and deselect
  132.  * the entries as we go
  133.  */
  134. SaveListerEntries:
  135.     PROCEDURE
  136.  
  137.     Handle = Arg( 1 )
  138.  
  139.     /* Get lister path. */
  140.     Lister Query Handle Path
  141.     FilePath = RESULT
  142.  
  143.     IF RC ~= 0 THEN DO
  144.         CALL OpusMessage 'Couldn''t get lister path.'
  145.         RETURN 0
  146.     END
  147.  
  148.     /* Make sure path is properly terminated */
  149.     IF Right( FilePath, 1 ) ~= ':' & Right( FilePath, 1 ) ~= '/' THEN DO
  150.         FilePath = FilePath'/'
  151.     END
  152.  
  153.     /* Get the selected entries */
  154.     Lister Query Handle SelEntries
  155.  
  156.     IF RC ~= 0 THEN DO
  157.         CALL OpusMessage 'Couldn''t get selected entries.'
  158.         RETURN 0
  159.     END
  160.  
  161.     Files = RESULT
  162.  
  163.     Lister Set Handle Busy On Wait
  164.  
  165.     /* Iterate over all selected entries */
  166.     DO WHILE Files ~= ''
  167.         /* Extract one entry name */
  168.         PARSE VAR Files . '"' Name '"' Files
  169.  
  170.         /* Write name to file */
  171.         IF WriteLN( 'List', FilePath||Name ) = 0 THEN DO
  172.             CALL OpusMessage 'Couldn''t write to temporary list file.'
  173.             Lister Set Handle Busy Off
  174.             Lister Refresh Handle
  175.             RETURN 0
  176.         END
  177.  
  178.         /* And deselect the file */
  179.         Lister Select Handle '"'Name'"' Off
  180.     END
  181.  
  182.     Lister Set Handle Busy Off
  183.     Lister Refresh Handle
  184.     RETURN 1
  185.  
  186.  
  187. /* Show a message in an Opus requester, with a suitable "header" */
  188. OpusMessage:
  189.     PROCEDURE
  190.  
  191.     Lf = '0a'x
  192.     Message = 'ShowVisage.dopus5:'Lf||Lf||Arg(1)
  193.     DOpus Request '"'Message'"' 'OK'
  194.     RETURN
  195.